import com.mongodb.MongoClient;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.bson.Document;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class test3 {
    static MongoClient mongoClient = new MongoClient("192.168.1.173", 27017);
    static MongoDatabase mDatabase = mongoClient.getDatabase("企查查");
    static MongoCollection collection = mDatabase.getCollection("31Error_List");

    public static void main(String[] args) throws IOException {
        Workbook workbook = new SXSSFWorkbook(10000);
        Sheet sheet = workbook.createSheet();

        Row row = sheet.createRow(0);
        int index = 0;
        row.createCell(index++).setCellValue("企业名称");

        FindIterable<Document> documents = collection.find();

        int rownum = 1;
        int count = 0;
        for (Document document : documents) {
            int cellnum = 0;

            count++;
            Row row1 = sheet.createRow(rownum++);
            row1.createCell(cellnum++).setCellValue(document.get("企业名称").toString());


            System.out.println("正在写入------------------------------");
        }

//        workbook.write(new FileOutputStream("C:\\Users\\jinghe\\192.168.1.173\\高新技术企业\\excel导出\\高新技术企业\\认定.xlsx"));
        workbook.write(new FileOutputStream("D:\\测试临时文件\\31失败.xls"));
        System.out.println("写去excel完毕*--------------------");
        System.out.println("条目数量："+count);
    }
}
